<?php
namespace app\admin\controller;

use app\common\controller\Back;

class Tool extends Back
{
    protected function initialize()
    {
        parent::initialize();
    }
    
    public function index()
    {
        $this->assign($this->site);
        
        return $this->fetch();
    }

    public function delete()
    {
        if($this->query['type'] == 'cache'){
            $this->clearCache();
        }elseif($this->query['type'] == 'runtime'){
            $this->clearRuntime();
        }
        $this->success('操作成功');
    }

    public function update()
    {
        if($this->query['type'] == 'type'){
            model('common/Type','loglic')->updateCount();
        }elseif($this->query['type'] == 'tag'){
            model('common/Tag','loglic')->updateCount();
        }
        $this->success('操作成功');
    }

    //清空缓存
    private function clearCache()
    {
        \think\facade\Cache::clear();
    }

    //清空临时文件
	private function clearRuntime()
    {
        $file = new \files\File();
        //删除应用日志目录
        $file->d_delete('./runtime/log');
        //删除模板缓存目录
        $file->d_delete('./runtime/cache');
        //删除应用缓存目录
        $file->d_delete('./runtime/temp');
	}
}